class BaseModel {
  /**
   * 构造函数
   * @param {Object} data 数据
   * @param {string} message 信息
   */
  constructor(message, data) {

    this.data = data

    this.msg = message
  }
}

class SuccessModel extends BaseModel {
  constructor(message = "操作成功", data = "", code = 0) {
    super(message, data)
    this.code = code
  }
}

class ErrorModel extends BaseModel {
  constructor(message = "操作失败", data = "", code = 1) {
    super(message, data)
    this.code = code
  }
}

class ReturnModel {
  /**
   * 构造函数
   * @param {Object} resobj 数据
   */
  constructor(resobj, code, message) {
    if (code) {
      resobj.code = code;
    }
    if (message) {
      resobj.msg = message;
    }
    if (resobj.code) {
      return new ErrorModel(resobj.msg ? resobj.msg : '操作失败', null, resobj.code);
    } else {
      return new SuccessModel(resobj.msg ? resobj.msg : '操作成功', resobj.data, resobj.code);
    }
  }
}

module.exports = {
  SuccessModel,
  ErrorModel,
  ReturnModel
}